home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Plug-In Power Pack for Netscape Communicator
/
Plug-In Power Pack for Netscape Communicator.iso
/
plugins
/
dataviews
/
dvtools
/
demos
/
telecomdemo
/
fixbox.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-06-16
|
8KB
|
230 lines
#ifndef lint
static char SccsId[]= "@(#)fixbox.c V1.8 3/17/95";
#endif
/*
| File name: fixbox.c
|========================================================================
|
| Copyright (c) 1990 -- V.I. Corporation
|
|========================================================================
*/
#include "simulate.h"
#include "tlc_fundecl.h"
#include "GRkeysym.h"
/***************** Begin Function Declarations *************/
LOCAL char *RandomSerialNumber V_P_((void));
/***************** End Function Declarations *************/
/*
* LoadFixboxView -- load the fixbox view, find the interesting objects,
* and create a drawport.
*/
void
LoadFixboxView (viewname)
char *viewname;
{
OBJECT drawing;
RECTANGLE area, dummy;
DATASOURCE ds;
DSVAR dsvar;
Fixbox.disp_info.view = TviLoad (viewname);
drawing = TviGetDrawing (Fixbox.disp_info.view);
/*
* Extract the interesting objects from the drawing. Also, find the center
* of the text input object to use as the input point for all key strokes.
*/
Fixbox.equip_type_str = TdrGetNamedObject (drawing, "EquipType");
Fixbox.equip_manuf_str = TdrGetNamedObject (drawing, "EquipManuf");
Fixbox.equip_ser_num_str = TdrGetNamedObject (drawing, "EquipSerialNum");
Fixbox.service_addr_str = TdrGetNamedObject (drawing, "ServiceAddress");
Fixbox.service_contact_str = TdrGetNamedObject (drawing, "ServiceContact");
Fixbox.confirm_input = TdrGetNamedObject (drawing, "ConfirmInput");
VOobBox (Fixbox.confirm_input, &area, &dummy);
Fixbox.input_point.x = area.ll.x + (area.ur.x - area.ll.x);
Fixbox.input_point.y = area.ll.y + (area.ur.y - area.ll.y);
/*
* Find the correct datasource variable and rebind it.
*/
ds = TdlGetNamedDataSource (TviGetDataSourceList (Fixbox.disp_info.view),
"Vars");
dsvar = TdsGetNamedDsVar (ds, "ConfirmString");
Fixbox.confirm_str = (CHAR *) TdsvGetBuffer (dsvar);
/*
* Get the limits of the drawing and use them as the screen position
* for the drawport.
*/
(VOID) VOobBox (drawing, &Fixbox.disp_info.drawing_area, &dummy);
Fixbox.disp_info.virt_pos.ll.x = Fixbox.disp_info.drawing_area.ll.x + 16383;
Fixbox.disp_info.virt_pos.ll.y = Fixbox.disp_info.drawing_area.ll.y + 16383;
Fixbox.disp_info.virt_pos.ur.x = Fixbox.disp_info.drawing_area.ur.x + 16383;
Fixbox.disp_info.virt_pos.ur.y = Fixbox.disp_info.drawing_area.ur.y + 16383;
(VOID) GRvcs_to_scs (&Fixbox.disp_info.virt_pos.ll,
&Fixbox.disp_info.screen_pos.ll);
(VOID) GRvcs_to_scs (&Fixbox.disp_info.virt_pos.ur,
&Fixbox.disp_info.screen_pos.ur);
/*
* Create the drawport and initialize the other fields in the
* structure.
*/
Fixbox.disp_info.drawport = TdpCreateStretch (StatusScreen,
Fixbox.disp_info.view,
&Fixbox.disp_info.virt_pos,
&Fixbox.disp_info.drawing_area);
Fixbox.disp_info.drawn = NO;
Fixbox.disp_info.active = NO;
Fixbox.part_ptr = NULL;
}
/*
* InputInFixboxDrawport -- handle input to the fixbox drawport.\
*/
void
InputInFixboxDrawport (location)
OBJECT location;
{
INT key;
DV_POINT screen_pt;
CHAR *name;
/*
* If there is a key press, then it's one of two things. If it's a
* newline, then if the input string is not empty, then erase the
* drawport. If it's any other keypress, then build a fake location
* object to stuff the input into the text input object.
*/
if (VOloType (location) == V_KEYPRESS)
{
key = VOloKeySym (location);
if ('\r' == key || '\n' == key || XK_Linefeed == key)
{
if (*Fixbox.confirm_str != '\0')
{
Fixbox.part_ptr->fix_time = SimParams.iter_number + FIX_DELAY;
OutputInfo ((INT) SimParams.iter_number, FIX_ORDER,
Fixbox.part_ptr->part_name, Fixbox.confirm_str);
EraseSubView (&Fixbox.disp_info, (RECTANGLE *) NULL);
}
}
else
{
WINEVENT* we = VOloWinEventGet (location);
(VOID) TdpWorldToScreen (Fixbox.disp_info.drawport,
&Fixbox.input_point, &screen_pt);
we->loc.x = screen_pt.x;
we->loc.y = screen_pt.y;
(VOID) TloWinEventSetup (location, we, StatusScreen,
Fixbox.disp_info.drawport);
(VOID) VUerHandleLocEvent (location);
}
}
/*
* If the the object picked is the quit icon, then take away the
* drawport without fixing the part.
*/
else if ((name = TloGetSelectedObjectName (location)))
{
if (strcmp (name, "Quit") == 0)
EraseSubView (&Fixbox.disp_info, (RECTANGLE *) NULL);
}
else
ToFront (&Fixbox.disp_info);
}
/*
* SetupFixbox -- set up the fixbox drawport based on the part being fixed.
*/
void
SetupFixbox (part_struct, part_type)
PART_STRUCT *part_struct;
char *part_type;
{
INT indx;
/*
* Find the type of the part.
*/
if (strncmp (part_type, "crt", 3) == 0)
indx = CRT;
else if (strncmp (part_type, "x25net", 6) == 0)
indx = X25NET;
else if (strncmp (part_type, "cpu", 3) == 0)
indx = CPU;
else if (strncmp (part_type, "mux", 3) == 0)
indx = MUX;
else if (strncmp (part_type, "switch", 6) == 0)
indx = SWITCH;
else if (strncmp (part_type, "genpac", 6) == 0)
indx = GENPAC;
else if (strncmp (part_type, "pbx", 3) == 0)
indx = PBX;
else if (strncmp (part_type, "chcard", 6) == 0)
indx = CHAN_CARD;
else if (strncmp (part_type, "tel", 3) == 0)
indx = TELEPHONE;
/*
* Load up the view with the correct information using a random
* serial number.
*/
VOvtSetString (Fixbox.equip_type_str, Parts[indx].type);
VOvtSetString (Fixbox.equip_manuf_str, Parts[indx].manuf);
VOvtSetString (Fixbox.equip_ser_num_str, RandomSerialNumber ());
VOvtSetString (Fixbox.service_addr_str, Parts[indx].service_addr);
VOvtSetString (Fixbox.service_contact_str, Parts[indx].service_contact);
*Fixbox.confirm_str = '\0';
Fixbox.part_ptr = part_struct;
}
/*
* MoveFixboxDrawort -- move the fixbox drawport to a new position.
*/
void
MoveFixboxDrawport (location)
OBJECT location;
{
RECTANGLE old_pos;
old_pos.ll.x = Fixbox.disp_info.screen_pos.ll.x;
old_pos.ll.y = Fixbox.disp_info.screen_pos.ll.y;
old_pos.ur.x = Fixbox.disp_info.screen_pos.ur.x;
old_pos.ur.y = Fixbox.disp_info.screen_pos.ur.y;
MoveDrawport (StatusScreen, &Fixbox.disp_info.screen_pos, location);
NewPosition (&Fixbox.disp_info, &old_pos);
}
LOCAL CHAR ser_num_str[12];
/*
* RandomSerialNumber -- compute a random serial number with a letter in
* the first position, numbers in the 2nd through 9th position, and letters
* in the last two positions.
*/
LOCAL char *RandomSerialNumber
V_P_ ((void))
{
INT i;
ser_num_str[0] = 'A' + (CHAR) (VUfrand ()* 26.0);
for (i = 1; i < 9; i++)
ser_num_str[i] = '0' + (CHAR) (VUfrand ()* 10.0);
ser_num_str[9] = 'A' + (CHAR) (VUfrand ()* 26.0);
ser_num_str[10] = 'A' + (CHAR) (VUfrand ()* 26.0);
ser_num_str[11] = '\0';
return ser_num_str;
}